package com.nccsjz.back.user.service;

import java.sql.SQLException;

import com.nccsjz.back.user.dao.UserDAO;
import com.nccsjz.base.BaseService;
import com.nccsjz.pojo.User;
import com.nccsjz.utils.CardException;
/**
 * LoginService类用于处理与登录操作相关的逻辑
 * 
 * @author jason	2009-10-14
 * @since 1.0
 */
public class UserService extends BaseService {

	
	/**
	 * isLeagle方法检查用户登录信息是否合法
	 *  
	 * @param user	用户信息
	 * @return	true：合法	false:不合法
	 * @throws SQLException 
	 */
	public boolean isLeagle(User user) throws SQLException{
		boolean flag = false;
		try{
			openCon();
			flag = new UserDAO(con).isExists(user);
		}finally{
			closeCon();
		}
		return flag;
	}
	
	/**
	 * changePwd方法用于更新登录用户的密码
	 * 
	 * @param user	用户对象
	 * @return	更新是否成功的标识
	 * @throws SQLException
	 * @throws CardException
	 */
	public boolean changePwd(User user) throws SQLException, CardException{
		boolean flag = false;		
		try{			
			openCon();			
			flag = new UserDAO(con).update(user);
		}finally{
			closeCon();
		}		
		return flag;
	}
	
	/**
	 * 根据用户编号查询用户对象
	 * 
	 * @param id 用户编号
	 * @return	用户对象
	 * @throws SQLException
	 */
	public User findUserById(Long id) throws SQLException{
		User user = null;
		try{
			openCon();
			user = new UserDAO(con).getUser(id);
		}finally{
			closeCon();
		}
		return user; 
	}
	
}
